﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cricket.LinqData;
using Cricket.LinqModel;
public partial class AddMatchType : System.Web.UI.Page
{
    #region Variable Declaration
    IDataRepository _dataObject = new DataRepository();
    MatchType matchType;
    List<MatchType> matchTypes;
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //if (Session["AdminUser"] != null)
            //    SessionManager.CurrentUser = (LoggedInUser)Session["AdminUser"];
            HttpCookie cookie = Request.Cookies["Admin"];
            if (cookie == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                if (Request.QueryString["Id"] != null)
                {
                    fillMatchType(Request.QueryString["Id"].ToString());
                }
            }
        }
    }

    private void fillMatchType(string MatchTypeId)
    {
        matchType = new MatchType(_dataObject);
        matchType.Id = Convert.ToInt32(MatchTypeId);
        matchType.GetMatchTypeById();
        if (matchType.Id != 0)
        {
            txtType.Text = matchType.Type;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        matchType = new MatchType(_dataObject);
        matchType.Type = txtType.Text;
        matchType.IsActive = true;
        matchType.IsDeleted = false;
        if (Request.QueryString["Id"] != null)
        {
            matchType.DateUpdated = System.DateTime.UtcNow;
            matchType.Id = Convert.ToInt32(Request.QueryString["Id"].ToString());
            matchType.UpdateMatchType();
            layerSuccess.InnerHtml = "<strong>Success!</strong> Match type updated successfully.";
            layerSuccess.Attributes.Add("style", "display:block;");
        }
        else
        {
            matchType.DateAdded = System.DateTime.UtcNow;
            matchType.Create();
            layerSuccess.InnerHtml = "<strong>Success!</strong> Match type added successfully.";
            layerSuccess.Attributes.Add("style", "display:block;");
        }
        clearControl();
    }
    private void clearControl()
    {
        txtType.Text = string.Empty;
    }
    protected void btnView_Click(object sender, EventArgs e)
    {
        Response.Redirect("ViewMatchType.aspx");
    }

}